#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# @author: luohong
# @contact: luohong_studio@163.com
# @time: 2018/7/27
# @desc: 函数

# 函数参数
# 定义名为compare函数，需传x,y参数
def compare(x,y):
    if x > y:
        print(x,"is max num")
    elif x == y:
        print("equal")
    else:
        print(y,"is max num")
a = 100
b = 10
# 调用compare函数，传人参数
compare(a,b)

# 局部变量和全局变量
global_str = "haha"
global_str2 = "haha"
# 局部使用方法
def localFun(global_str):
    print("global_str="+global_str)
    global_str = "keke"
    print('Changed local global_str to', global_str)

# 使用global语句改变global_str2值
def localFun2():
    global global_str2
    print("global_str2=" + global_str2)
    global_str2 = "xixi"
    print('Changed global global_str2 to', global_str2)

localFun(global_str)
print(global_str)
localFun("lala")
print(global_str)
localFun2()
print(global_str2)

# 默认参数值

def defultParam(msg,time=1):
    print(msg*time)

defultParam("hello")
defultParam("hello",3)

# 关键字参数
def keyParam(a,b=24,c=25):
    print("======")
    print("a=",a,"\nb=",b,"\nc=",c)

keyParam(1,c=0)
keyParam(b=3,a=2)

# 可变参数
def complexFun(name="luo",*years,**about):
    print("name = ",name)
    for i in years:
        print("years = ",i)
    for first,second in about.items():
        print("about = ",first,second)

complexFun("luohong",2018,2017,age=25,birthday="1993-03-19")

# return、pass语句
def rebackData(age):
    if age < 18:
        return "children"
    elif 18 <= age < 100:
        return "adult"
    else:
        pass
print(rebackData(16))
print(rebackData(25))
print(rebackData(200))

def testDoc():
    '''
    测试文档
    :return:
    '''
    print("hehe")

testDoc()
print(testDoc.__doc__)
